﻿using Microsoft.AspNetCore.Mvc;
using NewRetail.Application.Components.Platform;
using NewRetail.Application.Components.Platform.Entity;
using NewRetail.Application.Core;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace NewRetail.Api.Controllers
{
    [NewRetailRoute("pos-day-sum")]
    public class PosDaySumController : BaseController<PosDaySum>
    {
        private readonly IPosDaySumService posDaySumService;
        public PosDaySumController(IPosDaySumService posDaySumService)
        {
            this.posDaySumService = posDaySumService;
        }

        public override async Task<ResponseEntity<PagedResultDto<PosDaySum>>> QueryPaging([FromBody] PagingRequestDto dto)
        {
            var res = await base.QueryPaging(dto);

            if (res.Data?.Items?.Any() ?? false)
            {
                res.Data.Items = await this.posDaySumService.AttachGoodsInfo(res.Data.Items.ToArray());
                res.Data.Items = await this.posDaySumService.AttachWarehouse(res.Data.Items.ToArray());
            }

            return res;
        }
    }
}
